package com.lagou.homework;

import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class Bean implements WritableComparable<Bean> {

    private int num;

    // 将Bean对象作为key，利用shuffle机制的自动排序，对数据排序
    @Override
    public int compareTo(Bean o) {

        if(this.num>o.getNum()){
            return 1;
        }else if(this.num < o.getNum()){
            return -1;
        }else{
            return 0;
        }
    }

    @Override
    public void write(DataOutput out) throws IOException {

        out.writeInt(num);
    }

    @Override
    public void readFields(DataInput in) throws IOException {

        this.num = in.readInt();
    }

    public Bean() {
    }

    public Bean(int num) {

        this.num = num;
    }


    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    @Override
    public String toString() {
        return ""+num;
    }
}
